package com.Threecharacters.Poly_.Polyarr.Case1;

public class Test {
    public static void main(String[] args) {

        //多态数组(数组+多态)+向下转型(父类强转为子类)+类型判断(instanceof)
        Person[] persons = new Person[5];

        persons[0] = new Person("jack",20);
        persons[1] = new Student("tome",19,100);
        persons[2] = new Student("Yell",20,90);
        persons[3] = new Teacher("White",35,12000);
        persons[4] = new Student("Fort",45,10000);

        for (int i = 0; i < persons.length; i++) {

            if(persons[i] instanceof Student) {
                Student person = (Student) persons[i];
                person.study();
            } else if(persons[i] instanceof  Teacher) {
                Teacher person = (Teacher) persons[i];
                person.teach();
            } else if(persons[i] instanceof  Person) {
                ;
            } else {
                System.out.println("输入的类型有误");
            }
            System.out.println(persons[i].say());

        }

    }

}
